using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;

namespace RBSViewer
{
    public partial class PeoplePicker : Form
    {
        private const string RESOURCESWEBSERVICE = "_vti_bin/PSI/Resource.asmx";
        private const string TIMESHEETWEBSERVICE = "_vti_bin/PSI/Timesheet.asmx";
        RBSViewer.ResourceWsc.Resource Resource = new RBSViewer.ResourceWsc.Resource();
        RBSViewer.TimesheetWsc.TimeSheet Timesheet = new RBSViewer.TimesheetWsc.TimeSheet();
        public Boolean defaultassignmentowner;
        public String SelectedUserName;
        public Guid SelectedUserGuid;

        public PeoplePicker()
        {
            InitializeComponent();
        }

        public void PopulateControl()
        {
            PickerList.ValueMember = "RES_UID";
            PickerList.DisplayMember = "RES_NAME";
            
            if (defaultassignmentowner)
            {
                Resource.Url = MainForm.PWAURL + RESOURCESWEBSERVICE;
                Resource.Credentials = CredentialCache.DefaultCredentials;
                ResourceWsc.ResourceDataSet myds = Resource.ReadUserList(ResourceWsc.ResourceActiveFilter.Active);
                PickerList.DataSource = myds.Tables["Resources"];
            }
            else
            {
                //Want timesheet approvers
                Timesheet.Url = MainForm.PWAURL + TIMESHEETWEBSERVICE;
                Timesheet.Credentials = CredentialCache.DefaultCredentials;
                TimesheetWsc.ResourceDataSet myds = Timesheet.ReadTimesheetApprovers(Guid.Empty);
                PickerList.DataSource = myds.Tables["Resources"];
            }
        }

        private void PickerList_DoubleClick(object sender, EventArgs e)
        {
            SelectedUserGuid = (Guid)PickerList.SelectedValue;
            SelectedUserName = PickerList.Text;
            this.Hide();
        }
    }
}